package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.util.ConfigUtil;

import com.util.BODY;
import com.util.HttpRequest;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.ReadConfig;
import com.util.SessionInfo;

/**
 * 缴存历史记录
 * @author 
 */
@Controller
@RequestMapping("/dwxxbgcontroller")
public class dwxxbgcontroller {

	private static final Logger logger = Logger.getLogger(dwxxbgcontroller.class);
	Map map  = new HashMap();
	List list = new ArrayList();
	  
	/**
	 * @param request
	 * @return
	 */
	@RequestMapping("/test")
	@ResponseBody
	public String entryinterface(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路劲
		String interfaceUrl = ReadConfig.readValue();
		SessionInfo sessionInfo = new SessionInfo();
		Map reqMap = new HashMap();
		BODY b=new BODY();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ124");
		//接口参数
		reqMap.put("LOGUserName","admin");
		reqMap.put("OpenKey",sessionIn.getKEY());
		b.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",b);
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		logger.info("接口返回内容:"+retMap);
		if(retMap.get("RETURNCODE").equals("100")){
			Map retMap1 = (Map) retMap.get("body");
			List l=(List) retMap1.get("RETDATA");
				Map m=(Map) l.get(0);
				m.put("DWZH", sessionIn.getDWZH());
			logger.info("接口返回内容:"+result);
			if(result != null){
				Map resMap = JSONUtil.toMap(result);
					map.put("code", 0); 
					map.put("msg", retMap.get("RETURNDESC"));
					map.put("data",retMap1.get("RETDATA"));
					list.add(resMap);
					response.setHeader("Content-type", "text/html;charset=UTF-8");
					response.setCharacterEncoding("UTF-8");
					String jsonString = JSONUtil.ToJsongString2(map);
					PrintWriter pw = response.getWriter();
					pw.write(jsonString);
			}
		}
		return null;
	}
	@RequestMapping("/bg")
	@ResponseBody
	public String bg(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit,String bDWYB,String bJCYH,String bDWJCBL,String bGRJCBL,String bDWFRDBXM,String bSJHM,String bCWFZR,String bCWFZRDH,String bKHYH,String bZH,String bDWDZXX,String bDWFXR,String bJBRSJHM,String DWZH,String DWMC,String DWYB,String DWFRDBXM,String DH,String CWFZR,String CWFZRDH,String KHYH,String ZH,String JCYH,String DWJCBL,String GRJCBL,String DWDZXX,String DWFXR,String JBRSJHM) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路劲
		String interfaceUrl = ReadConfig.readValue();
		BODY b=new BODY();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ163");
		//接口参数
		reqMap.put("LOGUserName", "admin");
		reqMap.put("OpenKey",sessionIn.getKEY());
		//原信息
		b.setDWZH(DWZH);
		b.setDWMC(DWMC);
		b.setDWYB(DWYB);
		b.setFRDB(DWFRDBXM);
		b.setDH(DH);
		b.setCWFZR(CWFZR);
		b.setCWFZRDH(CWFZRDH);
		b.setKHYH(KHYH);
		b.setZH(ZH);
		b.setJCYH(JCYH);
		b.setDWJCBL(DWJCBL);
		b.setGRJCBL(GRJCBL);
		b.setDWDZYX(DWDZXX);
		b.setDWFXR(DWFXR);
		b.setJBRSJH(JBRSJHM);
		//变更后的
		b.setBGHDWMC(DWMC);
		//reqMap.put("BGHDWMC",DWMC);
		//reqMap.put("BGHDWYB",bDWYB);
		b.setBGHDWYB(DWYB);
		//reqMap.put("BGHFRDB",bDWFRDBXM);
		b.setBGHFRDB(bDWFRDBXM);
		//reqMap.put("BGHDH",bSJHM);
		b.setBGHDH(bSJHM);
		//reqMap.put("BGHCWFZR",bCWFZR);
		b.setBGHCWFZR(bCWFZR);
		//reqMap.put("BGHCWFZRDH",bCWFZRDH);
		b.setBGHCWFZRDH(bCWFZRDH);
		//reqMap.put("BGHKHYH",bKHYH);
		b.setBGHKHYH(bKHYH);
		//reqMap.put("BGHZH",bZH);
		b.setBGHZH(bZH);
		//reqMap.put("BGHJCYH",bJCYH);
		b.setBGHJCYH(bJCYH);
		//reqMap.put("BGHDWJCBL",bDWJCBL);
		b.setBGHDWJCBL(bDWJCBL);
		//reqMap.put("BGHGRJCBL",bGRJCBL);
		b.setBGHGRJCBL(bGRJCBL);
		//reqMap.put("BGHDWDZYX",bDWDZXX);
		b.setBGHDWDZYX(bDWDZXX);
		reqMap.put("BGHDWFXR",bDWFXR);
		b.setBGHDWFXR(bDWFXR);
		reqMap.put("BGHJBRSJH",bJBRSJHM);
		b.setBGHJBRSJH(bJBRSJHM);
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		
		logger.info("接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("data",resMap.get("RETDATA"));
				map.put("msg",  resMap.get("RETURNDESC").toString());
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
}
